import request from '@/utils/request'

// interface 限制 添加表单对象的类型(请求体的类型)
export interface IAddNoticeform {
  name: string
}

export const noticeAddRequest = (body: IAddNoticeform) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    url: '/admin/notice-category/create',
    method: 'post',
    data: body,
  })
}

export interface INoticeListItemRes {
  categoryId: string
  createTime: string
  flag: boolean
  name: string
  updateTime: string
  _id: string
}
export interface INoticeListRes {
  list: INoticeListItemRes[]
  pageNum: number
  pageSize: number
  total: number
}

export const noticeListRequest = (pageNum = 1, pageSize = 10) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<INoticeListRes>>({
    url: '/admin/notice-category/list',
    method: 'get',
    params: { pageNum, pageSize },
  })
}

export const noticeDelByIdRequest = (categoryId: string) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    // url: '/admin/notice-category/delete/:id',
    url: '/admin/notice-category/delete/' + categoryId,
    method: 'delete',
  })
}
export const noticeUpdateByIdRequest = (categoryId: string, name: string) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    // url: '/admin/notice-category/delete/:id',
    url: '/admin/notice-category/update/' + categoryId,
    method: 'put',
    data: { name },
  })
}
